package service;

import java.util.List;
import dao.Usertemp;
import dao.UsertempDAO;
import org.apache.log4j.Logger;
import java.security.MessageDigest;

public class UsertempService {
	private UsertempDAO usertempDao;
	public static Logger log = Logger.getLogger(UsertempService.class);

	public Usertemp isValid(String username, String password) {
		List<Usertemp> resultTemp = usertempDao.findByUsername(username);
		Usertemp usertemp;
		if (null==resultTemp || resultTemp.size()==0){
			return null;
		}
		else
			{
				usertemp=resultTemp.get(0);
				if (usertemp.getPassword().equals(password)){
					return usertemp;
				}
				else
					return null;
			}
	}
	
	public List<Usertemp> emailSearch(String email) {
		List<Usertemp> resultTemp = usertempDao.findByEmail(email);
		if (null==resultTemp || resultTemp.size()==0){
			return null;
		}
		else
		{
			return resultTemp;
		}
	}
	public Usertemp isValidRnd(String rnd) {
		List<Usertemp> resultTemp = usertempDao.findByRnd(Integer.valueOf(rnd));
		if (null==resultTemp || resultTemp.size()==0){
			return null;
		}
		else
		{
			return resultTemp.get(0);
		}
	}
	
	public UsertempDAO getUsertempDao() {
		return usertempDao;
	}

	public void setUsertempDao(UsertempDAO usertempDao) {
		this.usertempDao = usertempDao;
	}
}
